import React, {useState} from 'react';
import {Modal} from 'react-native';

const useModal = () => {
  const [isVisible, setIsVisible] = useState(false);
  const show = () => {
    if (!isVisible) {
      setIsVisible(true);
    }
  };
  const hide = () => setIsVisible(false);
  const RenderModal = (props) => (
    <>
      {isVisible && (
        <Modal {...props} onRequestClose={hide} visible={isVisible}>
          {props.children}
        </Modal>
      )}
    </>
  );
  return {
    show,
    hide,
    RenderModal,
  };
};

export default useModal;
